﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Xml.Linq;

namespace TfL
{
    public class StationLocation
    {
        public double Latitude { get; set; }
        public double Longitude { get; set; }
        public string Name { get; set; }

        public static StationLocation[] Load(string file)
        {
            return Load(File.Open(file, FileMode.Open));
        }
        public static StationLocation[] Load(Stream stream)
        {
            XDocument document = XDocument.Load(stream);
            XNamespace ns = XNamespace.Get("");
            var locations = from station in document.Descendants(ns + "wpt")
                            select new StationLocation()
                                       {
                                           Latitude = double.Parse(station.Attribute("lat").Value),
                                           Longitude = double.Parse(station.Attribute("lon").Value),
                                           Name = station.Attribute("desc").Value
                                       };
            return locations.ToArray();
        }
    }
}
